package cn.openea.perpartner.space.web.controller;


import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.meily.util.UserContext;
import cn.openea.perpartner.space.web.entity.SpaceNotice;
import cn.openea.perpartner.space.web.service.ISpaceNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 基础公告(Notice)表控制层
 *
 * @author Weird077
 * @since 2023-03-23 14:27:21
 */
@Api(tags = "海上新空间")
@RestController
@RequestMapping("/space/notice")
public class SpaceNoticeController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ISpaceNoticeService spaceNoticeService;

    @ApiOperation("公告列表")
    @PostMapping("/list")
    public TableDataInfo selectNoticeList(@RequestBody SpaceNotice notice) {
        startPage();
        List<SpaceNotice> list = this.spaceNoticeService.selectNoticeList(notice);
        return getDataTable(list);
    }
    @ApiOperation("最新公告")
    @GetMapping("/latest")
    public AjaxResult selectLatest() {
        return success(spaceNoticeService.selectLatest());
    }
    @ApiOperation("公告详情")
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(this.spaceNoticeService.getById(id));
    }

    @ApiOperation("新增公告")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SpaceNotice notice) {
        notice.setCreateUser(UserContext.getUserId());
        notice.setUpdateUser(UserContext.getUserId());
        return success(this.spaceNoticeService.save(notice));
    }

    @ApiOperation("编辑公告")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SpaceNotice notice) {
        notice.setUpdateUser(UserContext.getUserId());
        return success(this.spaceNoticeService.updateById(notice));
    }

    @ApiOperation("删除公告")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody  List<Long> idList) {
        return success(this.spaceNoticeService.removeByIds(idList));
    }
}

